﻿using System.Threading.Tasks;

namespace Sidvall.UI.ViewModels
{
    public sealed class PingFederateIdentityProviderControlViewModel : ControlViewModelBase
    {
        #region Public Members

        #region UserName

        private string _UserName = string.Empty;
        public string UserName
        {
            get
            {
                return _UserName;
            }
            set
            {
                if (value == null)
                    value = string.Empty;
                if (_UserName == value)
                    return;
                _UserName = value;
                RaisePropertyChanged(nameof(UserName));
                RaisePropertyChanged(nameof(CanLogOn));
            }
        }

        #endregion
        #region CanLogOn

        public bool CanLogOn
        {
            get
            {
                if (this.IsBusy)
                    return false;
                if (string.IsNullOrWhiteSpace(this.UserName))
                    return false;
                return true;
            }
        }

        #endregion

        // Commands
        #region LogOnAsync

        public async Task LogOnAsync(string password)
        {
            if (string.IsNullOrWhiteSpace(password))
                return;

            var startUrl = string.Empty;
            try
            {
                using (var busyManager = new Sidvall.Data.BusyManager(this))
                {

                }
            }
            catch (System.Exception ex)
            {
                var message = Sidvall.SystemContext.Current.SystemExceptionManager.GetMessage(ex);
                message = "User name: " + this.UserName +
                    System.Environment.NewLine + System.Environment.NewLine +
                    "startUrl: " + startUrl +
                    System.Environment.NewLine + System.Environment.NewLine +
                    message;
                await Sidvall.UI.SystemContext.Current.DialogManager.ShowDialogErrorMessageAsync(ex);
            }
        }

        #endregion

        #endregion
        #region Constructors

        public PingFederateIdentityProviderControlViewModel()
        {
        }

        #endregion
    }
}
